/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - core/math/types/Neon
// Copyright (c) 2014.  All Rights Reserved
//
// File:		AEMath_Neon.inl
// Author:		Gianluca Belardelli
// Date:		03/06/2014
//
/////////////////////////////////////////////////////////////////////////
#ifndef _AEMATH_NEON_INL_
#define _AEMATH_NEON_INL_

AE_FORCEINLINE AEQuadFloat32 AE_CALL AEMath::QuadReciprocal( const AEQuadFloat32 &qfValue )
{
	AEQuadFloat32 r0 = vrecpeq_f32( qfValue ); // estimate
	AEQuadFloat32 r1 = vmulq_f32( r0, vrecpsq_f32( qfValue, r0 )); // pass1
	return vmulq_f32( r1, vrecpsq_f32(  qfValue, r1 )); // pass2
}

AE_FORCEINLINE AEQuadFloat32 AE_CALL AEMath::QuadReciprocalSquareRoot( const AEQuadFloat32 &qfValue )
{
	AEQuadFloat32 r0 = vrsqrteq_f32( qfValue ); // estimate
	AEQuadFloat32 e0 = vmulq_f32(r0, r0);
	AEQuadFloat32 r1 = vmulq_f32( vrsqrtsq_f32(  qfValue, e0 ), r0 ); // pass1
	AEQuadFloat32 e1 = vmulq_f32( r1, r1 );		
	return vmulq_f32( vrsqrtsq_f32( qfValue, e1 ), r1 ); // pass2
}

AE_FORCEINLINE AEQuadFloat32 AE_CALL AEMath::QuadReciprocalTwoIter( const AEQuadFloat32 &qfValue )
{
	return QuadReciprocal( qfValue );
}

AE_FORCEINLINE AEQuadFloat32 AE_CALL AEMath::QuadReciprocalSquareRootTwoIter( const AEQuadFloat32 &qfValue )
{
	return QuadReciprocalSquareRoot( qfValue );
}

#endif // _AEMATH_NEON_INL_
